package com.blockchain.wmm.core.controller;

import com.blockchain.wmm.block.bean.BaseData;
import com.blockchain.wmm.block.bean.Block;
import com.blockchain.wmm.block.bean.ResultGenerator;
import com.blockchain.wmm.common.exception.TrustSDKException;
import com.blockchain.wmm.core.requestBody.BlockRequestBody;
import com.blockchain.wmm.core.service.BlockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author  wangzun
 * chaincode
 * */
@RestController
@RequestMapping("/block")
public class BlockController {
    @Resource
    private BlockService blockService;

    @PostMapping("/add")
    public BaseData addBlock(@RequestBody BlockRequestBody blockRequestBody) throws TrustSDKException {
        //优先校验key的合法性,若为非法key,则不放行
       /* if(blockService.check(blockRequestBody) != null) {
            return ResultGenerator.genFailResult(blockService.check(blockRequestBody));
        }*/
        return ResultGenerator.genSuccessResult(blockService.addBlock(blockRequestBody));
    }
    @GetMapping("/query")
    public BaseData queryBlock() {
        return ResultGenerator.genSuccessResult(blockService.query());
    }
}
